package cn.edu.zut.score.controller.student;

import cn.edu.zut.score.core.domain.PageResponse;
import cn.edu.zut.score.core.domain.RestResponse;
import cn.edu.zut.score.core.dto.request.MarkRequest;
import cn.edu.zut.score.core.dto.request.ReplyPageRequest;
import cn.edu.zut.score.core.dto.response.GradeResponse;
import cn.edu.zut.score.core.dto.response.GroupResponse;
import cn.edu.zut.score.core.dto.response.ReplyResponse;
import cn.edu.zut.score.service.IGradeService;
import cn.edu.zut.score.service.IGroupService;
import cn.edu.zut.score.service.IReplyInfoService;
import cn.edu.zut.score.service.IReplyService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zby
 * @date 2021/06/30
 */
@RestController
@RequestMapping("/student/reply")
@ApiModel("答辩相关api")
@CrossOrigin
public class StudentReplyController {

    @Autowired
    private IReplyService iReplyService;

    @Autowired
    private IReplyInfoService iReplyInfoService;

    @Autowired
    private IGradeService iGradeService;

    @Autowired
    private IGroupService iGroupService;

    @ApiOperation("分页获取当前用户答辩")
    @PostMapping("/list")
    public RestResponse<PageResponse<ReplyResponse>> getAllReplys(@RequestBody ReplyPageRequest replyPageRequest) {
        return iReplyService.getCurrentStudentAllReplys(replyPageRequest);
    }

    @ApiOperation("根据ID获取答辩详情")
    @GetMapping("/{replyid}")
    public RestResponse<ReplyResponse> getReplyById(@PathVariable("replyid") Long replyid) {
        return iReplyService.getReplyById(replyid);
    }

    @ApiOperation("根据ID查询答辩")
    @GetMapping("/data/{replyid}")
    public RestResponse<List<Integer>> getStuDataById(@PathVariable("replyid") Long replyid) {
        return iReplyInfoService.getStuDataById(replyid);
    }

    @ApiOperation("获取小组信息")
    @GetMapping("/group/{groupid}")
    public RestResponse<GroupResponse> getGroupById(@PathVariable("groupid") Long groupid) {
        return iGroupService.getGroupById(groupid);
    }

    @ApiOperation("当前学生根据ID预约答辩")
    @PutMapping("/{replyid}")
    public RestResponse<ReplyResponse> inline(@PathVariable("replyid") Long replyid) {
        return iReplyInfoService.inline(replyid);
    }

    @ApiOperation("根据答辩ID获取本人成绩")
    @GetMapping("/grade/{replyid}")
    public RestResponse<List<GradeResponse>> getScoreById(@PathVariable("replyid") Long replyid) {
        return iGradeService.getScoreByReplyId(replyid);
    }

    @ApiOperation("评分")
    @PostMapping("/mark")
    public RestResponse<String> mark(@RequestBody MarkRequest markRequest) {
        return iGradeService.mark(markRequest);
    }

    @ApiOperation("获取本人某个答辩的成绩分析")
    @PostMapping("/analyse/{replyid}")
    public RestResponse<List<Double>> getAnalyse(@PathVariable("replyid") Long replyId) {
        return iGradeService.getAnalyse(replyId);
    }
}
